/**
 * @author 黄波
 * 创建日期：2011Oct 10, 2011
 * TODO// N/A
 */
package com.platform.res.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Properties;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

/**
 * 更新资源配置信息
 */
public class UpdateResProfileAction extends ResourceSupport {

	private String[] values;

	public String[] getValues() {
		return values;
	}

	public void setValues(String[] values) {
		this.values = values;
	}

	@Override
	public String execute() throws Exception {
		//加载系统配置文件
		String systemProfile = "/system.properties";
		InputStream stream = new FileInputStream(new File(ServletActionContext.getServletContext().getRealPath("/") + systemProfile));
		OutputStream out = new FileOutputStream(new File(ServletActionContext.getServletContext().getRealPath("/") + systemProfile));
		Properties properties = new Properties();
		properties.load(stream);
		stream.close();
		properties.setProperty("icon_size", values[0]);
		properties.setProperty("content_size", values[1]);
		properties.store(out, "update");
		out.flush();
		out.close();
		
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		PrintWriter writer = response.getWriter();
		writer.flush();
		writer.write("<script>alert('设置成功！');history.back();</script>");
		writer.close();
		return null;
	}
}
